package com.yhsimon.inet;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class TestInetAddress {
    public static void main(String[] args) {
        try {
            //查询本机地址
            System.out.println(InetAddress.getByName("localhost"));
            System.out.println(InetAddress.getByName("127.0.0.1"));
            System.out.println(InetAddress.getLocalHost());

            //查询网站IP地址
            InetAddress inetAddress = InetAddress.getByName("www.baidu.com");
            System.out.println(inetAddress);


            //常用方法
            System.out.println(inetAddress.getAddress());
            System.out.println(inetAddress.getCanonicalHostName());//规范的名字
            System.out.println(inetAddress.getHostAddress());      //inet
            System.out.println(inetAddress.getHostName());         //域名 或者 自己电脑的名字
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
